using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KBE_HotFix
{
    public static class AckChecker
    {
        public const Byte Ret_Error = 0;
        public const Byte Ret_Success = 1;
        private static Dictionary<Byte, string> errorMessages = new Dictionary<byte, string>();

        public static bool Check(Byte code, Action<string> errorHandler = null)
        {
            if(code != Ret_Success)
            {
                if(errorHandler == null)
                {
                    return false;
                }

                string errMsg;
                if(!errorMessages.TryGetValue(code, out errMsg))
                {
                    errMsg = string.Format("Request Failed, Server Return Code : {0}", code);
                }
                errorHandler.Invoke(errMsg);
                return false;
            }
            return true;
        }

        public static void RegisterError(Byte code, string msg)
        {
            errorMessages[code] = msg;
        }
    }
}
